package glemipsc;

import glemipsc.implementations.Argument;
import glemipsc.implementations.Implementation;
import glemipsc.implementations.Instruction;
import glemipsc.instructions.Expression;

import java.io.Serializable;
import java.util.List;

public class ConstantString implements Expression, Serializable {
	private String str;
	private Type type;
	private Address addr;

	public ConstantString(String str) {
		this.str = str.substring(1, str.length() - 1);
		type = new TypeArray(new TypeChar(), this.str.length() + 1);
	}

	public Type getType() {
		return type;
	}

	public int getImmediateValue() {
		// TODO: Return string address
		return 0;
	}

	public boolean isImmediate() {
		return true;
	}

	public Address getStoreAddress() {
		return addr;
	}

	public boolean isStored() {
		return true;
	}

	public void setStoreAddress(Address addr) {
		this.addr = addr;
	}

	public int getStoredSize() {
		return type.sizeOf();
	}
	
	public String toString() {
		return str;
	}

	public void computeInstruction(Argument result, List<Instruction> instructions, Function func) {
		Implementation impl = GLEMipsC.compiler.getEnvironment().implementation;
		instructions.add(impl.getMov(result, impl.getImmediate(this.getImmediateValue())));
	}
}
